<template>
  <el-dialog v-dialogDrag class="dialogStyleMiddle" :title="dialogTitle" :visible="dialogVisible" :before-close="lookCancel">
    <el-form v-if="dialogVisible" :id="idPrint" ref="dialogForm" :model="LookDialogForm" label-width="auto">
      <el-col :span="12">
        <el-form-item label="企业名称：" prop="name">{{ LookDialogForm.name }}</el-form-item>
      </el-col>
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="企业类型：" prop="enterpriseType">-->
      <!--          <span v-if="LookDialogForm.enterpriseType === '0'">一般企业</span>-->
      <!--          <span v-if="LookDialogForm.enterpriseType === '1'">监管单位</span>-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <el-col :span="12">
        <el-form-item label="企业性质：" prop="nature">{{ LookDialogForm.nature }}</el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="企业地址：">
          {{ currentProvince }}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="详细地址：" prop="address">{{ LookDialogForm.address }}</el-form-item>
      </el-col>
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="信用代码：" prop="creditCodePic">{{ LookDialogForm.creditCodePic }}</el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="企业法人：" prop="legalperson">{{ LookDialogForm.legalperson }}</el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="法人电话：" prop="legalpersonMobile">{{ LookDialogForm.legalpersonMobile }}</el-form-item>-->
      <!--      </el-col>-->
      <el-col :span="12">
        <el-form-item prop="contacts">
          <label slot="label">联&nbsp;&nbsp;系&nbsp;&nbsp;人：</label>
          {{ LookDialogForm.contacts }}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="联系电话：" prop="phone">{{ LookDialogForm.phone }}</el-form-item>
      </el-col>
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="身份证号：" prop="idNumber">{{ LookDialogForm.idNumber }}</el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="销售代表：" prop="seller">-->
      <!--          {{ LookDialogForm.seller }}-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="客服代表：" prop="counterpart">-->
      <!--          {{ LookDialogForm.counterpart }}-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="资质证书：" prop="qualificationUrl">{{ LookDialogForm.qualificationUrl }}</el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col>-->
      <!--        <el-form-item prop="unitCreditCodePicUrl">-->
      <!--          <span slot="label">企业信用&nbsp;&nbsp;&nbsp;&nbsp;<br>代码扫描件：</span>-->
      <!--          &lt;!&ndash; 附件回显 &ndash;&gt;-->
      <!--          <file-view ref="fileView" style="margin-top:-10px;" :edit-file-list="editFileList" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-form>
    <!--    <span slot="footer" class="dialog-footer">-->
    <!--      <el-button size="medium" @click="lookCancel">取消</el-button>-->
    <!--      <el-button size="medium" type="primary" @click="print"></el-button>-->
    <!--    </span>-->
  </el-dialog>
</template>

<script>
// 附件回显
// import FileView from '@/components/FileUplode/FileView'
import { selectFileById } from '@/api/file/file.js'
import { getBasisById } from '@/api/enterprise/basis'
export default {
  name: 'Details',
  components: {
    // FileView
  },
  props: {
    cityOptions: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      dialogTitle: '',
      dialogVisible: false,
      idPrint: '',
      currentProvince: '',
      // 查看对话框表单
      LookDialogForm: {
        id: '',
        name: '',
        nature: '',
        creditCodePic: '',
        unitCreditCodePicUrl: '',
        qualificationUrl: '',
        province: '',
        city: '',
        area: '',
        address: '',
        legalperson: '',
        legalpersonMobile: '',
        idCard: '',
        idNumber: '',
        contacts: '',
        phone: '',
        enterpriseType: '',
        checkStatus: '',
        enterpriseExpiryTime: '',
        seller: '',
        counterpart: ''
      },
      editFileList: [],
      natureData: []
    }
  },
  created() {
    this.getDicts('enterprise_nature').then(response => {
      this.natureData = response.data.rows
    })
  },
  methods: {
    detailsItem(id) {
      this.dialogTitle = '企业详情'
      this.resetForm('dialogForm')
      this.getEnterpriseInfo(id)
      this.dialogVisible = true
      this.idPrint = id
    },
    // 查看对话框取消功能
    lookCancel() {
      this.dialogVisible = false
      this.resetForm('dialogForm')
      this.editFileList = []
      // this.$refs.fileView.emptyFile()
    },
    // 打印按钮功能
    print() {
      const subOutputRankPrint = document.getElementById(this.idPrint)
      const newContent = subOutputRankPrint.innerHTML
      const oldContent = document.body.innerHTML
      document.body.innerHTML = newContent
      window.print()
      window.location.reload()
      document.body.innerHTML = oldContent
      return false
    },
    getEnterpriseInfo(id) {
      getBasisById(id).then(resp => {
        if (resp) {
          this.LookDialogForm.id = resp.data.id
          this.LookDialogForm.name = resp.data.name
          this.LookDialogForm.nature = resp.data.nature
          for (var i in this.natureData) {
            if (this.LookDialogForm.nature === this.natureData[i].dictValue) {
              this.LookDialogForm.nature = this.natureData[i].dictLabel
            }
          }
          this.LookDialogForm.creditCodePic = resp.data.creditCodePic
          this.LookDialogForm.unitCreditCodePicUrl = resp.data.unitCreditCodePicUrl
          if (resp.data.unitCreditCodePicUrl) {
            this.selectFildListByIds(resp.data.unitCreditCodePicUrl)
          }
          this.LookDialogForm.qualificationUrl = resp.data.qualificationUrl
          this.LookDialogForm.seller = resp.data.seller
          this.LookDialogForm.counterpart = resp.data.counterpart
          this.LookDialogForm.legalperson = resp.data.legalperson
          this.LookDialogForm.legalpersonMobile = resp.data.legalpersonMobile
          this.LookDialogForm.idCard = resp.data.idCard
          this.LookDialogForm.idNumber = resp.data.idNumber
          this.LookDialogForm.contacts = resp.data.contacts
          this.LookDialogForm.phone = resp.data.phone
          this.LookDialogForm.enterpriseType = resp.data.enterpriseType
          this.LookDialogForm.checkStatus = resp.data.checkStatus
          this.LookDialogForm.enterpriseExpiryTime = resp.data.enterpriseExpiryTime
          this.LookDialogForm.address = resp.data.address
          // 翻译地址
          this.currentProvince = this.getRegnaion(resp.data.province, resp.data.city, resp.data.area)
        }
      })
    },
    getRegnaion(province, city, area) {
      const sheng = this.cityOptions.find(item => item.value === province)
      const shi = sheng.children.find(item => item.value === city)
      const xian = shi.children.find(item => item.value === area)
      return sheng.label + shi.label + xian.label
    },
    // 根据附件id查询附件信息
    selectFildListByIds() {
      var _this = this
      var fileIds = this.LookDialogForm.unitCreditCodePicUrl
      selectFileById(fileIds).then(resp => {
        if (resp) {
          _this.editFileList = resp.data
        } else {
          _this.msgError(resp.message)
        }
      })
    }
  }
}
</script>

<style>

</style>
